package com.codes.demo.maopao;
/**
 * @Description 
 * @Date 2020/7/15 11:56
 * @Created  peanut
 */
public class MaoPao {

    public static void main(String[] args) {

        int[] arr = {1,1,2,0,9,33,21,7,13,3,35,65,22};

        MaoPao.bubble2(arr);
        for(int i = 0;i<arr.length;i++){
            System.out.print(arr[i]+",");
        }


        System.out.println();

    }


    public static void bubble2(int[] a ) {
        int j, k = a.length;
        boolean flag = true;//发生了交换就为true, 没发生就为false
        while (flag) {
            flag = false;//每次开始排序前，都设置flag为未排序过
            for (j = 1; j < k; j++) {
                if (a[j - 1] > a[j]) {
                    int temp;
                    temp = a[j - 1];
                    a[j - 1] = a[j];
                    a[j] = temp;
                    //表示交换过数据;
                    flag = true;
                }
            }
            k--;//减小一次排序的尾边界
        }
    }

}